package com.geek.spring.boot.autoconfigure;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.ApplicationRunner;
import org.springframework.boot.autoconfigure.condition.ConditionalOnNotWebApplication;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;

/**
 * 自定义的自动装配实现，在非web的环境下，输出自定文案，该文案可由配置属性的my.springboot.msg配置。
 * <p>如果要临时关闭该自动装配，可修改配置属性my.springboot.enabled为false
 *
 */
@ConditionalOnProperty(prefix = "my.springboot", name = "enabled", matchIfMissing = true)
@ConditionalOnNotWebApplication
@EnableConfigurationProperties(MySpringBootProperties.class)
public class MySpringBootAutoConfiguration {
    private final static Logger logger = LoggerFactory.getLogger(MySpringBootAutoConfiguration.class);

    @Bean
    public ApplicationRunner mySpringBootRunner(MySpringBootProperties properties) {
        return args -> {
            logger.info(properties.getMsg());
        };
    }
}
